import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: GodK
 * Date: 2024-06-01
 * Time: 16:54
 */
public class Mysqlcheck {
    public static void check(String s1, String s2) throws SQLException {
        DataSource dataSource = new MysqlDataSource();
        ((MysqlDataSource) dataSource).setUrl("jdbc:mysql://127.0.0.1:3306/practice?characterEncoding=utf8&useSSL=false");
        ((MysqlDataSource) dataSource).setUser("root");
        ((MysqlDataSource) dataSource).setPassword("123");
        Connection connection = dataSource.getConnection();
        //String sql = "select ?,? from student;";
        String sql = "select " + s1 + ", " + s2 + " from student;";
        //String sql = "select * from student;";
        PreparedStatement statement = connection.prepareStatement(sql);
        //statement.setString(1,s1);
        //statement.setString(2,s2);
        ResultSet n = statement.executeQuery();
        while (n.next()){
            System.out.print(n.getString("id"));
            System.out.print(" ");
            System.out.println(n.getString("name"));
        }
        n.close();
        statement.close();
        connection.close();
    }
}
